﻿namespace exercise.链表
{
    public class Solution
    {
        public ListNode<int> ReverseList(ListNode<int> head)
        {
            ListNode<int> prev = null;
            ListNode<int> curr = head;

            while (curr != null)
            {
                ListNode<int> temp = curr.Next;
                curr.Next = prev;
                prev = curr; //永远保存前一个
                curr = temp; //永远是下一个
            }

            //prev是尾结点，也是新的头结点
            head = prev;

            return head;
        }
    }
}
